﻿using Finbook.GameApp.Models;
using System;
using System.Linq;

namespace Finbook.GameApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //GameV1Start();
                GameV2Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }

        private static void GameV2Start()
        {
            var player = new RoleV2(300);
            var monster = new RoleV2(300);
            for (int i = 0; i < 5; i++)
            {
                player.Skills.Add(new Skill(i));
                monster.Skills.Add(new Skill(i));
            }
            Console.WriteLine("游戏开始");
            while (true)
            {
                var playSkill = player.Skills.ElementAt(new Random().Next(0, player.Skills.Count));
                monster.BeHit(playSkill);
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                Console.WriteLine($"怪兽被攻击，收到伤害：{playSkill.SkillDamage},当前血量：{monster.HP}");
                Console.ForegroundColor = ConsoleColor.White;
                if (monster.HP <= 0)
                {
                    break;
                }

                var monsterSkill = monster.Skills.ElementAt(new Random().Next(0, monster.Skills.Count));
                player.BeHit(monsterSkill);
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine($"怪兽被攻击，收到伤害：{monsterSkill.SkillDamage},当前血量：{player.HP}");
                Console.ForegroundColor = ConsoleColor.White;
                if (player.HP <= 0)
                {
                    break;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            if (player.HP <= 0)
            {
                Console.WriteLine("怪兽胜利！");
            }
            else
            {
                Console.WriteLine("玩家胜利！");
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("游戏结束");
        }

        private static void GameV1Start()
        {
            var player = new Role(300,20);
            var monster = new Role(500, 10);
            Console.WriteLine("游戏开始");
            while (true)
            {
                monster.BeHit(player.Damage);
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                Console.WriteLine($"怪兽被攻击，收到伤害：{player.Damage},当前血量：{monster.HP}");
                Console.ForegroundColor = ConsoleColor.White;
                if (monster.HP<=0)
                {
                    break;
                }

                player.BeHit(monster.Damage);
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine($"怪兽被攻击，收到伤害：{monster.Damage},当前血量：{player.HP}");
                Console.ForegroundColor = ConsoleColor.White;
                if (player.HP <= 0)
                {
                    break;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            if (player.HP<=0)
            {
                Console.WriteLine("怪兽胜利！");
            }
            else
            {
                Console.WriteLine("玩家胜利！");
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("游戏结束");
        }
    }
}
